﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class OperatorsList : System.Web.UI.UserControl
{
    BankDataDataContext db = new BankDataDataContext();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Roles.IsUserInRole("Administrator"))
        {
            Response.Redirect("~/Account/Login.aspx");
        }
    }

    protected void OperatorsListGridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            LinkButton linkButton = (LinkButton)e.Row.FindControl("DeleteLink");
            linkButton.CommandArgument = GridView1.DataKeys[e.Row.RowIndex]["OperatorId"].ToString();
            linkButton = (LinkButton)e.Row.FindControl("TransferClientsLink");
            linkButton.CommandArgument = GridView1.DataKeys[e.Row.RowIndex]["OperatorId"].ToString();
        }
    }

    protected void DeleteClicked(object sender, EventArgs e)
    {
        LinkButton linkButton = (LinkButton)sender;
        Session.Add("operatorId", linkButton.CommandArgument);
        Response.Redirect("~/Admin/DeleteOperator.aspx");
    }

    protected void TransferClientsClicked(object sender, EventArgs e)
    {
        LinkButton linkButton = (LinkButton)sender;
        Session.Add("operatorId", linkButton.CommandArgument);
        Response.Redirect("~/Admin/TransferClients.aspx");
    }

    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string operatorLogin = GridView1.Rows[GridView1.SelectedIndex].Cells[3].Text;
        var bankOperator = from bankOperators in db.aspnet_Users where bankOperators.UserName == operatorLogin select bankOperators;
        string operatorId = bankOperator.First().Operator.OperatorId.ToString();
        Session.Add("id", operatorId);
        Response.Redirect("~/Admin/OperatorRegistrationEdit.aspx");
    }

}